package com.zwr.mvpdemo.net;

import android.util.Log;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

/**
 *   Created by zwr on 2017/5/3.
 */

public enum OKHttpFactory {
    INSTANCE;
    private final OkHttpClient okHttpClient;
    OKHttpFactory() {
        //日志显示级别
        // HttpLoggingInterceptor.Level level= HttpLoggingInterceptor.Level.HEADERS;

        //新建log拦截器
        HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
         @Override
            public void log(String message) {
             Log.e("网络请求","OkHttp====Message:"+message);
            }
         });

     //  loggingInterceptor.setLevel(level);
        okHttpClient = new OkHttpClient.Builder()
                //失败重连
                .retryOnConnectionFailure(true)
                //time out
                .readTimeout(10, TimeUnit.MINUTES)//读
                .connectTimeout(10,TimeUnit.MINUTES)//连
                .writeTimeout(10,TimeUnit.MINUTES)//写
                .addInterceptor(loggingInterceptor)//添加拦截器
                .build();
    }

    public OkHttpClient getOkHttpClient() {
        return okHttpClient;
    }
}
